<template>
  <el-dialog title="修改商品 " :visible.sync="editVisible" width="90%" @close="editClose">
    <!-- 执行步骤提示 -->
    <el-steps :active="active" finish-status="success" align-center class="mb25">
      <el-step title="基本信息"></el-step>
       <el-step title="商品参数"></el-step>
        <el-step title="商品属性"></el-step>
      <el-step title="商品图片"></el-step>
      <el-step title="商品内容"></el-step>
      <el-step title="完成"></el-step>
    </el-steps>
    <!-- 树形tab页 form -->
    <el-form :model="editFormData" :rules="editFormRules" ref="editFormRef" label-width="100px">
      <el-tabs tab-position="left" v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="基本信息" name="0">
          <!-- 基本信息 -->
          <el-form-item label="商品名称" prop="goods_name" size="small">
            <el-input v-model="editFormData.goods_name"></el-input>
          </el-form-item>
          <el-form-item label="商品价格(元)" prop="goods_price" size="small">
            <el-input v-model="editFormData.goods_price" type="number"></el-input>
          </el-form-item>
          <el-form-item label="商品数量" prop="goods_number" size="small">
            <el-input v-model="editFormData.goods_number" type="number"></el-input>
          </el-form-item>
          <el-form-item label="商品重量" prop="goods_weight" size="small">
            <el-input v-model="editFormData.goods_weight" type="number"></el-input>
          </el-form-item>
        </el-tab-pane>
         <el-tab-pane label="商品参数" name="1">
           <!-- 商品参数 -->
    

        </el-tab-pane>
         <el-tab-pane label="商品属性" name="2">

        </el-tab-pane>
        <el-tab-pane label="商品图片" name="3">
         <!-- 商品图片 -->
            <el-upload
              :action="uploadUrl"
              :on-preview="handlePreview"
              :on-remove="handleRemove"
              list-type="picture"
              :on-success="handleSuccess"
              :headers="headersToken"
            >
              <el-button size="small" type="primary">点击上传</el-button>
            </el-upload>
        </el-tab-pane>
        <el-tab-pane label="商品内容" name="4">
          <!-- 富文本编辑器 -->
          <quill-editor v-model="editFormData.goods_introduce"></quill-editor>
        </el-tab-pane>
      </el-tabs>
    </el-form>
    <span slot="footer">
      <el-button @click="editVisible = false" size="small">取 消</el-button>
      <el-button type="primary" @click="editVisible = false" size="small">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  props: ["editFormData"],
  data() {
    return {
      editVisible: false,
      // 执行步骤提示
      active: 0,
      // 树形tab页 数据绑定name值
      activeName: "0",

      // 图片上传后台路径定义
      uploadUrl: "http://127.0.0.1:8888/api/private/v1/upload",
      //本地Authorization是绑定到axios请求上只有发送axios请求才会带token，element upload 自己封装的请求，所有要将 后台token要绑定到upload上面headers
      headersToken: {
        Authorization: window.sessionStorage.getItem("token"),
      },
      //验证规则
      editFormRules: {
        goods_name: [
          { required: true, message: "请输入分类名称", trigger: "blur" },
        ],
        goods_price: [
          { required: true, message: "请输入分类名称", trigger: "blur" },
        ],
        goods_number: [
          { required: true, message: "请输入分类名称", trigger: "blur" },
        ],
        goods_weight: [
          { required: true, message: "请输入分类名称", trigger: "blur" },
        ],
      },
    };
  },
  created() {},
  methods: {
    //显示弹出框
    showDialog() {
      this.editVisible = true;
    },
    // 弹出框显示与关闭
    editClose() {
      this.$refs.editFormRef.resetFields();
      this.editVisible = false;
    },
    handleClick() {
      // 实现步骤和tab切换联动// 将this.activeName字符串转化成number在赋给active
      this.active = parseInt(this.activeName);
    },
    //上传图片成功查看图片
    handlePreview(file) {
    //   console.log(file);
    //   this.pictureLook = file.response.data;
    //   (this.pictureName = file.name), (this.pictureVisible = true);
    },
    // 上传图片成功删除图片
    handleRemove(file) {
      // //删除时拿到虚拟路径下的图片路径tmp_path
      // const tmp_path_upload = file.response.data.tmp_path;
      // console.log(tmp_path_upload);
      // // 拿到虚拟路径下的图片路径tmp_path和goodFormData中pics中的图片数组对比-相同时的索引
      // const i = this.pics.findIndex((val, index, arr) => {
      //   return val.pic === tmp_path_upload;
      // });
      // // 将当前的索引对应的图片移除
      // this.pics.splice(i, 1);
      // //console.log(this.goodFormData)
    },
    // 图片上传成功时钩子函数 时调用 response后台接收的数据
    handleSuccess(response) {
      console.log(response)
      // 将图片信息对象拼接后台需要格式
      // const picturePath = { pic: response.data.tmp_path };
      // //将图片信息拼接后对象 push到goodFormData.pics数字中
      // this.pics.push(picturePath);
      // console.log(this.pics);
    }
  },
};
</script>

<style scoped>
</style>